<?php
/**  发布产品页面 异步取资源库数据的后台请求处理页面
 * Created by PhpStorm.
 * User: KaZeline
 * Date: 15-10-10
 * Time: 上午10:56
 */
if(!$_SESSION['sid'] || !$_POST['action']) exit('{"errMsg":"Invaild"}');
use \PFT\Db;
use \PFT\Resource;
include '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
Db::Conf($dbConf['localhost']);
include 'Resource.class.php';
$data = '{"errMsg":"Invaild"}';
switch ($_POST['action']) {
	case 'single':
        $id = $_POST['id']+0;
        if($id<0) break;
        $obj = new Resource(Db::Connect());
        $search = array('id'=>$id);
        $data = $obj->show($search, false, 0, 1);
        $data = $data[0];
        //把area里的数字替换成对应的省市名称
        $area = explode('|',$data['area']);
        $data['area']= '';
        $zhixia_array = array('1'=>1,'2'=>1,'3'=>1,'4'=>1,'32'=>1,'33'=>1,'34'=>1);
        if(is_array($area))
        foreach($area as $k=>$v){
            $sql = "select area_name from uu_area where area_id=$v limit 1";
            $stmt =Db::connect()->prepare($sql);
            $stmt->execute();
            $v = $stmt->fetch(\PDO::FETCH_ASSOC);
            $data['area'] .= '|'.$v['area_name'];
            if($zhixia_array[$area[$k]] && $k=='0'){
                $data['area'] .= $data['area'];
                break;
            }
        }
        if($data['jtype']+0>0) $data['jtype'].='A';
        if($data['jtype']=='0') $data['jtype'] = '其它';
        $data['area'] = ltrim($data['area'],'|');
        $data['bhjq'] = htmlspecialchars_decode($data['bhjq']);
        unset($data['apply_did']);
        unset($data['areacode']);
        unset($data['competitor']);
        unset($data['addtime']);
        unset($data['verify_status']);
		break;
    case 'list':
        /*
        $id = $_POST['city_id']+0;
        if($id<0) break;
        $currentPage = $_POST["currentPage"]? intval($_POST["currentPage"])-1:0;
        $pageSize    = $_POST["pageSize"]?intval($_POST["pageSize"]):10;
        $search = array('areacode'=>$id);
        $data  = $obj->show($search, false, $currentPage, $pageSize);
        */
        break;
	default:
		# code...
		break;
}


echo json_encode($data);
Db::Close();
exit;


function safetxt($text){
    $text = trim($text);
    $text = strip_tags ( $text );
    $text = htmlspecialchars ( $text, ENT_QUOTES,"UTF-8");
    $text = str_replace ( "'", "", $text );

    return $text;
}